#include <cstdio>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
#define ENDL '\n' // 将 endl 替换为 \n 取消缓冲区
using std::cin;
using std::cout;
using std::endl;
using std::string;

int str_to_int(string str_) {
  int num;
  std::stringstream ss(str_);
  ss >> num; // 从字符串流读取到 int
  return num;
}
void solve() {
  string str_ = "1";
  cin >> str_;
  while (str_.size() != 1) {
    if (str_.size() % 2 == 0) {
      string a = "", b = "";
      for (int i = 0; i < str_.size() / 2; ++i)
        a.push_back(str_[i]);
      for (int i = str_.size() / 2; i < str_.size(); ++i)
        b.push_back(str_[i]);
      int num = str_to_int(a) + str_to_int(b);
      str_ = std::to_string(num);
    } else {
      string a = "0", b = "";
      for (int i = 0; i < (str_.size() / 2); ++i)
        a.push_back(str_[i]);
      for (int i = str_.size() / 2; i < str_.size(); ++i)
        b.push_back(str_[i]);
      int num = str_to_int(a) + str_to_int(b);
      str_ = std::to_string(num);
    }
  }
  char x = str_[0];
  cout << x - 48 << endl;
}
int main() {
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  // test("1234567");
  // cout << int('9');
  return 0;
}